package com.crawler.crawler.service.impl;

import com.crawler.crawler.domain.BookImportConfig;
import com.crawler.crawler.mapper.BookImportConfigMapper;
import com.crawler.crawler.service.BookImportConfigServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BookImportConfigServerImpl implements BookImportConfigServer {

    @Autowired
    private BookImportConfigMapper mapper;
    /**
     * 查询所有配置
     *
     * @return
     */
    @Override
    public Map<String,String> selectConfigList(BookImportConfig bookImportConfig) {
        List<BookImportConfig> list=mapper.selectConfigList(bookImportConfig);
        Map<String,String> map=new HashMap<>();
        for (BookImportConfig config:list){
            map.put(config.getName(),config.getValue());
        }

        return map;
    }

    /**
     * 根据名称查询配置
     *
     * @return
     */
    @Override
    public BookImportConfig selectBookByName(String name) {
        return mapper.selectBookByName(name);
    }

    /**
     * 更新配置
     *
     * @return
     */
    @Override
    public int updateConfig(BookImportConfig bookImportConfig) {
        return mapper.updateConfig(bookImportConfig);
    }

    /**
     * 插入配置
     *
     * @return
     */
    @Override
    public int insertConfig(BookImportConfig bookImportConfig) {
        return mapper.insertConfig(bookImportConfig);
    }

}
